package com.dkd.day20250619;
import com.dkd.day20250616.TreeNode;

import java.util.ArrayList;
import java.util.List;


public class SolutioninorderTraversal {
    public static void main(String[] args) {

    }

    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     *
     * @param root TreeNode类
     * @return int整型一维数组
     */
    public int[] inorderTraversal (TreeNode root) {
        // write code here
        //左，根，右
        List<Integer> list = new ArrayList<Integer>();
        traversal(list, root);
        int [] res = new int[list.size()];
        for(int i=0;i<=res.length-1;i++){
            res[i] = list.get(i);
        }
        return res;
    }

    public List<Integer> traversal (List<Integer> list, TreeNode root) {
        // write code here
        if (root == null) {
            return list;
        }

        traversal(list, root.left);
        list.add(root.val);
        traversal(list, root.right);
        return list;
    }
}
